//
// Created by wyh on 2025-07-28 22:42.
//

#include <iostream>
#include <reflect/class_register.h>

using namespace std;
using namespace wyh::reflect;

class A : public Object
{
public:
    A() : m_name("A"), m_age(18)
    {}

    ~A()
    {}

    void f1()
    {
        cout << "f1" << endl;
    }

    int f2(const string &name, int age)
    {
        cout << "f2" << ":name=" << name << ",age=" << age << endl;
        return 88;
    }

public:
    string m_name;
    int m_age;
};

REGISTER_CLASS(A);
REGISTER_CLASS_FIELD(A, m_name, string);
REGISTER_CLASS_FIELD(A, m_age, int);
REGISTER_CLASS_METHOD(A, f1,void);
REGISTER_CLASS_METHOD(A, f2,int,const string&,int);

int main(int argc, char **argv)
{
    auto factory = Singleton<ClassFactory>::instance();
    Object *a = factory->create_class("A");

    string name;
    a->get<string>("m_name", name);

    cout << name << endl;

    int age;
    a->get<int>("m_age", age);

    cout << age << endl;

    a->set<string>("m_name", "kitty");
    a->set<int>("m_age", 30);

    a->get<string>("m_name", name);
    cout << name << endl;

    a->get<int>("m_age", age);
    cout << age << endl;

    a->call("f1");
    const string &name1 = "kitty";
    int age1 = 100;
    int ret = a->call<int>("f2", name1, age1);
    cout<<"ret="<<ret<<endl;

    return 0;
}
